package com.yu.crm.web;

import com.yu.crm.domain.pojo.AttendanceInfo;
import com.yu.crm.domain.pojo.AttendanceRecord;
import com.yu.crm.mapper.AttendanceInfoMapper;
import com.yu.crm.mapper.AttendanceRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

//@Component
class Demo2ServiceWithServletContextAware implements ServletContextAware {

    @Autowired
    AttendanceInfoMapper attendanceInfoMapper;

    @Autowired
    AttendanceRecordMapper attendanceRecordMapper;

    @Override
    public void setServletContext(ServletContext servletContext) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            public void run() {

//                List<AttendanceInfo> attendanceInfos = attendanceInfoMapper.selectList(null);
//                List<AttendanceRecord> attendanceRecords = attendanceRecordMapper.selectList(null);

                System.out.println("Demo2ServiceWithServletContextAware已经执行" + new SimpleDateFormat("HH:mm:ss").format (new Date()));
            }
        }, 1000, 1000 * 60); // 此时为一分钟执行一次 每次延迟一秒执行

    }

}

